from .base import KeyframeStrategy
from typing import List, Set
from ..models import FrameData

class ThresholdStrategy(KeyframeStrategy):
    def __init__(self, threshold: float):
        self.threshold = threshold

    def _rel_change(self, a: float, b: float) -> float:
        return (b - a) / max(a, b) if a != b else 0.0

    def detect(self, frames: List[FrameData]) -> Set[int]:
        keyframes = set()
        for i in range(1, len(frames)):
            if self._rel_change(frames[i-1].diff, frames[i].diff) >= self.threshold:
                keyframes.add(frames[i].id)
        return keyframes